package com.example.ktpspringboot.service.impl;

import com.example.ktpspringboot.entity.FileVO;
import com.example.ktpspringboot.service.FileService;
import com.example.ktpspringboot.utils.FileUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@Service
//加载指定的配置文件
public class FileServiceImpl implements FileService {

    @Value("${spring.servlet.multipart.location}")
    private String fileLocalPath;

    @Override
    public String upload(MultipartFile file,String homework) throws IOException {
        try {
            // 封装文件信息
            FileVO fileSaveDTO = FileUtil.handleFileSave(fileLocalPath, file);
            return "文件上传成功";
        } catch (Exception e) {
            e.printStackTrace();
            return "文件上传失败";
        }
    }
}
